import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/stock_out_order_detail_child_entity.dart';
import 'package:library_base/entities/stock_out_order_detail_entity.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/widget/multi_state_widget/multi_state_widget.dart';
import 'package:library_base/base/base_list_state.dart';
import 'package:module_wms/page/outbound_orders/as_order/order_detail/order_detail_controller.dart';
import 'package:module_wms/page/outbound_orders/as_order/order_detail/order_detail_page_ui.dart';

class OrderDetailPage extends StatefulWidget {
  const OrderDetailPage({Key? key}) : super(key: key);

  @override
  _OrderDetailPageState createState() => _OrderDetailPageState();
}

class _OrderDetailPageState extends BaseListState<StockOutOrderDetailEntity,
    StockOutOrderDetailChildEntity, OrderDetailPage, OrderDetailController> {
  @override
  OrderDetailController registerController() =>
      Get.find<OrderDetailController>();

  @override
  void onCreate() {
    super.onCreate();
    setTitle(MultiLanguage.detailsOfOutboundOrders.tr);
    setNavigationBarColor(ThemeUtil.getTheme().colorScheme.secondary);
  }

  @override
  void controllerOnCreate() {
    useRefresh = true;
    isCanRefresh = false;
    isCanLoad = false;
    enableControlFinishLoad = false;
    enableControlFinishRefresh = true;
    baseGetxController?.easyRefreshController = controller;
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return MultiStateWidget(
      emptyWidget: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            LocalImage('admin_empty',
                package: Constant.packAdmin(), width: 0.6.sw),
            Text(MultiLanguage.noSuchProduct.tr, style: TextStyles.textSecondary28),
            SizedBox(height: 80.h),
            Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              GradientButton(
                ThemeUtil.getTheme(),
                width: 0.4.sw,
                height: 80.w,
                text: MultiLanguage.reload.tr,
                onPressed: baseGetxController!.tryReLoad,
              ),
            ])
          ]),
      controller: baseGetxController!.multiControllerOut,
      child: Column(
        children: [
          Expanded(
            child: Container(
                color: ThemeUtil.getTheme().secondaryBgColor(),
                child: getListView(context, baseGetxController)),
          ),
        ],
      ),
    );
  }

  @override
  List<Widget> buildListItem(BuildContext context) {
    return baseGetxController!.listData.value.buildItem((index, element) {
      return GetBuilder<OrderDetailController>(
        builder: (logic) {
          return GestureDetector(
              onTap: () {},
              child: buildItem(
                element,
                index,
                preDistribution: baseGetxController!.preDistribution,
              ));
        },
      );
    }, dividingLine: () {
      return gapH18;
    });
  }
}
